<?php
namespace App\Models;

use DB;
use Illuminate\Database\Eloquent\Model;

/**
 * 用户粉丝表
 * @author lee
 *
 */
class UserFansM extends Model
{
    protected $table='lee_user_fans';
    static public $STable='lee_user_fans';
    
    protected $fillable = ['userid', 'fansid'];
    
    /**
     * 添加 粉丝记录
     * @param array $inputData,输入数据
     * 
     * ['userid'=>1,'fansid'=>11]
     */
    public static  function newFansItem(array $inputData){
        $userInst=new UserFansM($inputData);
        $userInst->save();
    }
    
    /**
     * 删除 粉丝记录
     * @param array $inputData,输入数据
     *
     * ['userid'=>1,'fansid'=>11]
     */
    public static  function deltFansItem(array $inputData){
        self::where($inputData)->delete();
    }
    
    /**
     * 依据用户id 返回其粉丝列表
     * 
     * @param bigint $userid 用户id
     */
    public static function getFans($userid){
        $fansTName=self::$STable;
        $userTName=UserM::$STable;    
        $sql="select 
        us.id as userid, us.name as username,us.avatar as avatar,
        us.height as height,us.weight as weight,
        us.address as address,us.bra as bra,us.underbustgirth as underbustgirth,
        us.fansnum as funsnum, us.avatar as avatar,us.sign as sign 
        
        from $userTName as us
        
        where id in (select fansid from $fansTName where userid =$userid)";
        return DB::select($sql);
    }
}

?>